import 'chat_message.dart';

class MessagePreview {
  final String userId;
  final String avatar;
  final String nickname;
  final ChatMessage lastMessage;
  final int unreadCount;

  MessagePreview({
    required this.userId,
    required this.avatar,
    required this.nickname,
    required this.lastMessage,
    required this.unreadCount,
  });

  factory MessagePreview.fromJson(Map<String, dynamic> json, String myId) {
    return MessagePreview(
      userId: json['userId'].toString(),
      avatar: json['avatar'],
      nickname: json['nickname'],
      lastMessage: ChatMessage.fromJson(json['lastMessage'], myId),
      unreadCount: json['unreadCount'] ?? 0,
    );
  }
}
